package com.wondersgroup.framework.sample.listener;

import com.wondersgroup.framework.sample.component.form.vo.CodeInfoVO;
import com.wondersgroup.framework.sample.component.form.vo.UserVO;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class InitFormDataListener
  implements ServletContextListener
{
  public void contextInitialized(ServletContextEvent event)
  {
    initUserData(event.getServletContext());
    initCodeInfoData(event.getServletContext());
  }

  public void initUserData(ServletContext context)
  {
    List userData = new ArrayList();

    for (int i = 1; i <= 20; ++i) {
      UserVO vo = new UserVO();
      vo.setBankName("中国银行");
      vo.setDateTime(new Date());
      vo.setCardNumber("00" + i);
      vo.setCardType("借记卡");
      vo.setCash(i + "000");
      vo.setCensusAddress("上海市万达");
      vo.setId(String.valueOf(i));
      vo.setEmail("Kiddy" + i + "@wondersgroup.com");
      vo.setName("Kiddy" + i);
      vo.setSex("0");
      vo.setDistrict("xuhui");
      vo.setIdcard("310113196308270814");
      vo.setPhone("24178888");
      vo.setCensus("城镇户口");
      if (i % 2 == 0) {
        vo.setSex("1");
      }
      else
        vo.setSex("2");

      vo.setZip("201112");
      vo.setNation("汉族");
      userData.add(vo);
    }

    context.setAttribute("userList", userData);
  }

  public void initCodeInfoData(ServletContext context) {
    List codeInfoData = new ArrayList();

    CodeInfoVO model1 = new CodeInfoVO();
    model1.setId(-1243064853740912639L);
    model1.setCode("shanghai");
    model1.setName("上海市");
    model1.setParent(null);
    model1.setValue("shanghai");
    model1.setText("上海市");
    codeInfoData.add(model1);
    CodeInfoVO model2 = new CodeInfoVO();
    model2.setId(2L);
    model2.setCode("beijing");
    model2.setName("北京市");
    model2.setValue("beijing");
    model2.setText("北京市");
    model2.setParent(null);
    codeInfoData.add(model2);

    CodeInfoVO model3 = new CodeInfoVO();
    model3.setId(3L);
    model3.setCode("xuhui");
    model3.setName("徐汇区");
    model3.setValue("xuhui");
    model3.setText("徐汇区");
    model3.setParent(model1);
    codeInfoData.add(model3);
    CodeInfoVO model4 = new CodeInfoVO();
    model4.setId(4L);
    model4.setCode("huangpu");
    model4.setName("黄浦区");
    model4.setValue("huangpu");
    model4.setText("黄浦区");
    model4.setParent(model1);
    codeInfoData.add(model4);

    CodeInfoVO model5 = new CodeInfoVO();
    model5.setId(5L);
    model5.setCode("chaoyang");
    model5.setName("朝阳区");
    model5.setValue("chaoyang");
    model5.setText("朝阳区");
    model5.setParent(model2);
    codeInfoData.add(model5);
    CodeInfoVO model6 = new CodeInfoVO();
    model6.setId(6L);
    model6.setCode("haidian");
    model6.setName("海淀区");
    model6.setValue("haidian");
    model6.setText("海淀区");
    model6.setParent(model2);
    codeInfoData.add(model6);

    CodeInfoVO model7 = new CodeInfoVO();
    model7.setId(7L);
    model7.setCode("fenglin");
    model7.setName("枫林街道");
    model7.setValue("fenglin");
    model7.setText("枫林街道");
    model7.setParent(model3);
    codeInfoData.add(model7);
    CodeInfoVO model8 = new CodeInfoVO();
    model8.setId(8L);
    model8.setCode("tianlin");
    model8.setName("田林街道");
    model8.setValue("tianlin");
    model8.setText("田林街道");
    model8.setParent(model3);
    codeInfoData.add(model8);

    CodeInfoVO model9 = new CodeInfoVO();
    model9.setId(9L);
    model9.setCode("waitan");
    model9.setName("外滩街道");
    model9.setValue("waitan");
    model9.setText("外滩街道");
    model9.setParent(model4);
    codeInfoData.add(model9);
    CodeInfoVO model10 = new CodeInfoVO();
    model10.setId(10L);
    model10.setCode("yuyuan");
    model10.setName("豫园街道");
    model10.setValue("yuyuan");
    model10.setText("豫园街道");
    model10.setParent(model4);
    codeInfoData.add(model10);

    CodeInfoVO model11 = new CodeInfoVO();
    model11.setId(11L);
    model11.setCode("qinghe");
    model11.setName("清和街道");
    model11.setValue("qinghe");
    model11.setText("清和街道");
    model11.setParent(model5);
    codeInfoData.add(model11);
    CodeInfoVO model12 = new CodeInfoVO();
    model12.setId(12L);
    model12.setCode("huxi");
    model12.setName("湖西街道");
    model12.setValue("huxi");
    model12.setText("湖西街道");
    model12.setParent(model5);
    codeInfoData.add(model12);

    CodeInfoVO model13 = new CodeInfoVO();
    model13.setId(13L);
    model13.setCode("huayuan");
    model13.setName("花园路街道");
    model13.setValue("huayuan");
    model13.setText("花园路街道");
    model13.setParent(model6);
    codeInfoData.add(model13);
    CodeInfoVO model14 = new CodeInfoVO();
    model14.setId(14L);
    model14.setCode("zhongguancun");
    model14.setName("中关村街道");
    model14.setValue("zhongguancun");
    model14.setText("中关村街道");
    model14.setParent(model6);
    codeInfoData.add(model14);

    context.setAttribute("codeInfoList", codeInfoData);
  }

  public void contextDestroyed(ServletContextEvent event)
  {
  }
}